<script src="__PUBLIC__/admin/js/jquery.min.js"></script>
<script src="__PUBLIC__/admin/kindeditor-4.1.7/kindeditor-min.js"></script>
<script src="__PUBLIC__/admin/kindeditor-4.1.7/kindeditor-all-min.js"></script>
<script>
$(function(){
    $("#nav_list option").on("click",function(){
        var val=$(this).val();
        // alert(val);
    })
})
</script>
<div class="row">
    <ol class="breadcrumb">
        <li><a href="{:U('Index/index')}"><span class="glyphicon glyphicon-home"></span></a></li>
        <li class="active">新闻设置</li>
    </ol>
</div><!--/.row-->

<script>
$(function(){
    $("#nav_list").val({$type});
    $("#nav_list").on("change",function(){
        var id=$(this).val();
                // alert(id);
        $.ajax({
            url:"{:U('News/getChange')}",
            type:"post",
            data:{"type":id},
            success:function(data){
                var str='';
                for (var i = 0; i < data.length; i++) {
                    str+='<tr>';
                    str+='<td>'+data[i]["title"]+'</td>';
                    str+='<td>'+data[i]["content"]+'</td>';
                    str+='<td>'+data[i]["imgurl"]+'</td>';
                    str+='<td>'+data[i]["author"]+'</td>';
                    str+='<td>'+data[i]["time"]+'</td>';
                    str+='<td><a href="{:U('News/newsDel')}&id='+data[i]["Id"]+'">删除</a></td>';
                    str+='</tr>';
                }
                $("#add_table tbody").html(str);
            }
        });
    })
})
</script>
<div class="row">
    <div class="col-lg-12">
        <h1 class="page-header">新闻资讯设置</h1>
    </div>
</div><!--/.row-->
<form action="{:U('News/addNews')}" method="post" enctype="multipart/form-data"> 
<div class="form-group">
    <select class="form-control" name="type" id="nav_list">
        <option value="1">行业新闻</option>
        <option value="2">企业新闻</option>
        <option value="3">技术新闻</option>
    </select>
</div>                           
<table data-toggle="table" data-url="tables/data2.json" class="table table-hover" id="add_table">
    <thead>
        <tr>
            <th>标题</th>
            <th>作者名</th>
            <th>上传图片</th>
            <th>内容</th>
            <th>时间</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
    <?php foreach($newslist as $k => $v) { ?>
        <tr>
            <td><?php echo $v["title"]; ?></td>
            <td><?php echo $v["author"]; ?></td>
            <td><?php echo $v["time"]; ?></td>
            <td><?php echo $v["content"]; ?></td>
            <td><img style="width:60px;" src="<?php echo $v['imgurl'];?>" alt=""></td>
            <td><a href="{:U('News/newsDel?id='.$v['Id'])}">删除</a></td>
        </tr>
    <?php } ?>
    </tbody>
</table>
    <div class="form-group">
        <label>标题设置</label>
        <input class="form-control" placeholder="请填写新闻的主标题" name="title" value="<?php echo $indexinfo['title']?>">
         <label>作者</label>
        <input class="form-control" placeholder="请填写作者的名字" name="author" value="<?php echo $indexinfo['author']?>">
    </div>
        <textarea id="editor_id" name="content" style="width:700px;height:300px;">
        </textarea>
        <div class="form-group">
            <label>上传图片</label>
            <input type="file" name="news">
            <p class="help-block">请上传图片，（大小小于2M）</p>
        </div>    
    <button type="submit" class="btn btn-primary">提交</button>
</form>
    <script charset="utf-8" src="/editor/kindeditor.js"></script>
    <script charset="utf-8" src="/editor/lang/zh-CN.js"></script>
    <script>
        KindEditor.ready(function(K) {
                window.editor = K.create('#editor_id');
        });
    </script>